//
//  bRINsvJLCFHomeActivityViewControllerhGuDnz.m
//  qcb_ios
//
//  Created by Ji on 2018/8/28.
//  Copyright © 2018年 ski. All rights reserved.
//

#import "bRINsvJLCFHomeActivityViewControllerhGuDnz.h"
#import "IpxzlFJLCFHomeRequestPfjhYJ.h"
#import "ZIyWqYJLCFHomeActivityDataModelgGtMcU.h"
#import "ahNNWiJLCFHomeActivityCellWZdeuW.h"

@interface bRINsvJLCFHomeActivityViewControllerhGuDnz ()
{
    NSInteger _pageNumber;
}
@property (nonatomic, strong) NSMutableArray *OtIqgvactivityArrUquhbr;

@end

@implementation bRINsvJLCFHomeActivityViewControllerhGuDnz

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.navigationBar.title = @"活动中心";
    self.tableView.frame = CGRectMake(0, NAVBAR_HEIGHT, FULL_WIDTH, self.view.height - NAVBAR_HEIGHT);
    self.tableView.backgroundColor = QTZ_Gray237;
    self.tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, FULL_WIDTH, 25)];
    
    [self loadData];
}

- (NSMutableArray *)OtIqgvactivityArrUquhbr
{
    if (!_OtIqgvactivityArrUquhbr) {
        _OtIqgvactivityArrUquhbr = [NSMutableArray array];
    }
    return _OtIqgvactivityArrUquhbr;
}

- (void)loadData
{
    
    [self.OtIqgvactivityArrUquhbr removeAllObjects];
    _pageNumber = 1;
    
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setSafeObject:@"2" forKey:@"type"];
    [params setSafeObject:@(_pageNumber) forKey:@"page"];
    
    [IpxzlFJLCFHomeRequestPfjhYJ postHomeActivityDataWithParams:params loadingInView:self.view success:^(jpWEYNJLCFHomeActivityResultModelpfIuTR *activity) {
        [self hideNoMoreDataNotice];
        if (activity.data.count > 0) {
            [self.OtIqgvactivityArrUquhbr addObjectsFromArray:activity.data];
        } else {
            self.tableView.tableHeaderView = nil;
            [self showNoMoreDataNotice:@"没有更多了"];
        }
        [self.tableView reloadData];
        [self endRefresh];
        
    } failure:^(NSString *error) {
        [self showNotice:error];
        [self endRefresh];
    }];
    
}

- (void)loadMoreData
{
    
    _pageNumber ++;
    
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setSafeObject:@"2" forKey:@"type"];
    [params setSafeObject:@(_pageNumber) forKey:@"page"];
    
    [IpxzlFJLCFHomeRequestPfjhYJ postHomeActivityDataWithParams:params loadingInView:self.view success:^(jpWEYNJLCFHomeActivityResultModelpfIuTR *activity) {
        if (activity.data.count > 0) {
            [self.OtIqgvactivityArrUquhbr addObjectsFromArray:activity.data];
        } else {
            [self showNoMoreDataNotice:@"没有更多了"];
        }
        [self.tableView reloadData];
        [self endLoadMore];
        
    } failure:^(NSString *error) {
        [self showNotice:error];
        [self endLoadMore];
    }];
    
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return self.OtIqgvactivityArrUquhbr.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 250 + 35;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, FULL_WIDTH, 15)];
    footerView.backgroundColor = [UIColor clearColor];
    return footerView;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 15;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    ahNNWiJLCFHomeActivityCellWZdeuW *cell = [ahNNWiJLCFHomeActivityCellWZdeuW dequeueReusableCellForTableView:tableView];
    cell.data = [self.OtIqgvactivityArrUquhbr objectAtIndex:indexPath.section];
    [cell reloadData];
    return cell;
}

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    //    if (indexPath.section == 1 || indexPath.section == 2) {
    
    if ([cell respondsToSelector:@selector(tintColor)]) {
        
        if (tableView == self.tableView) {
            
            CGFloat cornerRadius = 10.f;
            
            cell.backgroundColor = UIColor.clearColor;
            
            CAShapeLayer *layer = [[CAShapeLayer alloc] init];
            
            CGMutablePathRef pathRef = CGPathCreateMutable();
            
            CGRect bounds = CGRectInset(cell.bounds, 10, 0);
            
            if (indexPath.row == 0 && indexPath.row == [tableView numberOfRowsInSection:indexPath.section]-1) {
                
                CGPathAddRoundedRect(pathRef, nil, bounds, cornerRadius, cornerRadius);
                
            } else if (indexPath.row == 0) {
                
                CGPathMoveToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMaxY(bounds));
                
                CGPathAddArcToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMinY(bounds), CGRectGetMidX(bounds), CGRectGetMinY(bounds), cornerRadius);
                
                CGPathAddArcToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMinY(bounds), CGRectGetMaxX(bounds), CGRectGetMidY(bounds), cornerRadius);
                
                CGPathAddLineToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMaxY(bounds));
                
            } else if (indexPath.row == [tableView numberOfRowsInSection:indexPath.section]-1) {
                
                CGPathMoveToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMinY(bounds));
                
                CGPathAddArcToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMaxY(bounds), CGRectGetMidX(bounds), CGRectGetMaxY(bounds), cornerRadius);
                
                CGPathAddArcToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMaxY(bounds), CGRectGetMaxX(bounds), CGRectGetMidY(bounds), cornerRadius);
                
                CGPathAddLineToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMinY(bounds));
                
            } else {
                
                CGPathAddRect(pathRef, nil, bounds);
                
            }
            
            layer.path = pathRef;
            
            CFRelease(pathRef);
            
            layer.fillColor = [UIColor colorWithWhite:1.f alpha:1.f].CGColor;
            
            
            UIView *testView = [[UIView alloc] initWithFrame:bounds];
            
            [testView.layer insertSublayer:layer atIndex:0];
            
            testView.backgroundColor = UIColor.clearColor;
            
            cell.backgroundView = testView;
            
        }
        
    }
    
    //    }
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
